home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / jam / jamdisk7 / inc9110b.lzh / include / ctype.h < prev    next >
C/C++ Source or Header  |  1991-06-28  |  3KB  |  83 lines

  1. /*
  2.  * Libraries and headers for PDC release 3.3 (C) 1989 Lionel Hummel.
  3.  * PDC Software Distribution (C) 1989 Lionel Hummel and Paul Petersen.
  4.  * PDC I/O Library (C) 1987 by J.A. Lydiatt.
  5.  *
  6.  * This code is freely redistributable upon the conditions that this
  7.  * notice remains intact and that modified versions of this file not
  8.  * be included as part of the PDC Software Distribution without the
  9.  * express consent of the copyright holders.  No warrantee of any
  10.  * kind is provided with this code.  For further information, contact:
  11.  *
  12.  *  PDC Software Distribution    Internet:                     BIX:
  13.  *  P.O. Box 4006             or hummel@cs.uiuc.edu            lhummel
  14.  *  Urbana, IL  61801-8801       petersen@uicsrd.csrd.uiuc.edu
  15.  */
  16.  
  17. /*
  18.  * ctype.h - very efficient macros for classifying characters.
  19.  * note, these do _not_ test that the parameter is in range.
  20.  */
  21.  
  22. /*
  23.  *  3.3.91 sjw; ensure only done once, fix toupper(), tolower() to
  24.  *              only change when proper
  25.  * 28.6.91 sjw; fix isgraph(), isascii(), iscsym(), toint(),
  26.  *              toupper(), tolower() to evaluate argument once only
  27.  *              NOTE the use of ({}) is a GNU extension.
  28.  */
  29.  
  30. #ifndef __CTYPE_H__
  31. #define __CTYPE_H__
  32.  
  33. extern char _ctype[256];
  34.  
  35. #define _UPPER       (1)
  36. #define _LOWER       (1 << 1)
  37. #define _HEXIT       (1 << 2)
  38. #define _DIGIT       (1 << 3)
  39. #define _SPACE       (1 << 4)
  40. #define _CNTRL       (1 << 5)
  41. #define _PUNCT       (1 << 6)
  42. #define _OCTIT       (1 << 7)
  43.  
  44. /* standard */
  45.  
  46. #define isalnum(x)   (_ctype[(x)&0xff] & (_UPPER | _LOWER | _DIGIT))
  47. #define isalpha(x)   (_ctype[(x)&0xff] & (_UPPER | _LOWER))
  48. #define iscntrl(x)   (_ctype[(x)&0xff] & _CNTRL)
  49. #define isdigit(x)   (_ctype[(x)&0xff] & _DIGIT)
  50. #define isgraph(x) \
  51.         ({int y = x; \
  52.           (!(_ctype[(y)&0xff] & _CNTRL)) & ((y) != ' ');})
  53. #define islower(x)   (_ctype[(x)&0xff] & _LOWER)
  54. #define isprint(x)   (!(_ctype[(x)&0xff] & _CNTRL))
  55. #define ispunct(x)   (_ctype[(x)&0xff] & _PUNCT)
  56. #define isspace(x)   (_ctype[(x)&0xff] & _SPACE)
  57. #define isupper(x)   (_ctype[(x)&0xff] & _UPPER)
  58. #define isxdigit(x)  (_ctype[(x)&0xff] & _HEXIT)
  59.  
  60. #define tolower(x)   ({int y = x; isupper(y) ? y | 32 : y;})
  61. #define toupper(x)   ({int y = x; islower(y) ? y & ~32 : y;})
  62.  
  63. /* extras */
  64.  
  65. #define iswhite(x)   (_ctype[(x)&0xff] & _SPACE)
  66. #define isodigit(x)  (_ctype[(x)&0xff] & _OCTIT)
  67.  
  68. #define isascii(x)   ({int y = x; y >= 0 && y < 128;})
  69. #define iscsym(x) \
  70.         ({int y = x; \
  71.           (_ctype[y & 0xff] & (_UPPER | _LOWER | _DIGIT)) \
  72.           || (y == '_') \
  73.           || (y == '$');})
  74.  
  75. #define tocntrl(x)  (((((x)+1)&~96)-1)&127)
  76. #define toascii(x)  ((x) & 127)
  77. #define toint(x) \
  78.         ({int y = x; \
  79.          (int)((_ctype[y&0xff]&_DIGIT)?(y-'0'):((y|32)-'a'+10));})
  80.  
  81. #endif /* __CTYPE_H__ */
  82.  
  83.